/*
 * @Description: 
 * @Author: Liu Kunpeng
 * @Date: 2021-07-05 20:41:06
 */
/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

export function percentage(val) {
  const strVal = val.toString()
  const index = strVal.indexOf('.')
  let num = 0
  if (index > -1) {
    num = strVal.length - 1 - index
  }
  if (num > 2) {
    return Math.round(val * Math.pow(10, num)) / Math.pow(10, num - 2)
  } else {
    return Math.round(val * 100)
  }
}